import intiaData from '../state'
import {Map} from 'immutable'

function shoppingcarReducer(state=intiaData.get("shoppingcar"),action){
  switch (action.type){
      case "PinkProduct":
            let product=action.product
            let exist=false
            return state.update("item",(item,index)=>{
                const newItem=item.map((every)=>{
                   if(every.get("id")===product.get("id")){
                       exist=true
                       return every.merge(Map({count:every.get("count")+1}))
                   }
                   else{
                       return every
                   }
                })
                if(exist){
                    return newItem
                }
                else{
                    return item.push(product.merge(Map({count:1})))
                }
            })
      default:
          return state
  }
}
export default shoppingcarReducer